package com.nan.controller;

import com.nan.model.Student;
import com.nan.model.Teacher;
import com.nan.service.TeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LittleY
 * @date 2025/6/9
 * @description 教师管理控制器
 */
@Tag(name = "教师管理", description = "教师信息的增删改查接口")
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    /**
     * 根据ID查询教师信息
     * @param id 教师ID
     * @return 教师信息
     */
    @Operation(summary = "根据ID查询教师信息", description = "根据教师ID获取单个教师的详细信息")
    @GetMapping("/{id}")
    public Teacher getById(@Parameter(description = "教师ID") @PathVariable("id") Long id) {
        return teacherService.getById(id);
    }

    /**
     * 查询所有教师信息
     * @return 教师列表
     */
    @Operation(summary = "查询所有教师信息", description = "获取所有教师的列表信息")
    @GetMapping
    public List<Teacher> list() {
        return teacherService.list();
    }

    /**
     * 新增教师信息
     * @param teacher 教师信息
     * @return 是否成功
     */
    @Operation(summary = "新增教师信息", description = "添加一个新的教师信息")
    @PostMapping
    public boolean save(@Parameter(description = "教师信息") @RequestBody Teacher teacher) {
        return teacherService.save(teacher);
    }

    /**
     * 更新教师信息
     * @param teacher 教师信息
     * @return 是否成功
     */
    @Operation(summary = "更新教师信息", description = "根据教师ID更新教师信息")
    @PutMapping
    public boolean update(@Parameter(description = "教师信息") @RequestBody Teacher teacher) {
        return teacherService.updateById(teacher);
    }

    /**
     * 删除教师信息
     * @param id 教师ID
     * @return 是否成功
     */
    @Operation(summary = "删除教师信息", description = "根据教师ID删除教师信息")
    @DeleteMapping("/{id}")
    public boolean delete(@Parameter(description = "教师ID") @PathVariable("id") Long id) {
        return teacherService.removeById(id);
    }

    /**
     * 根据老师ID查询对应的学生列表
     * @param id 老师ID
     * @return 学生列表
     */
    @Operation(summary = "查询老师对应的学生列表", description = "根据老师ID获取对应的学生列表信息")
    @GetMapping("/{id}/with-teacher")
    public List<Student> getTeachersByStudentId(@Parameter(description = "老师ID") @PathVariable("id") Long id) {
        return teacherService.getStudentssByTeacherId(id);
    }
}
